var Core = {
	 //API_VER:"http://localhost:9000",
	 //IMG_VER:"http://localhost:9000/upload/",

	API_VER:"",
	IMG_VER:"/upload/",
	VERSION:"1.0.0",
	DOC_VER:"/pdf/",
	id2url: function(id, action) {
		return Core.IMG_VER+id;
	}
}
function SetLS(key, json){
	window.localStorage.setItem(key, JSON.stringify(json));
}

function GetLS(key){
	var str = window.localStorage.getItem(key);
	if (str != null && str != "")
		return JSON.parse(str);
	else
		return false;
}
function ClearLS(key){
	localStorage.clear();
}

function locaHref(url){
	window.location.href = url;
}
function openHref(url){
	window.open(url);
}

function jieUrljing(){  
    var a=window.location.href.substring(window.location.href.indexOf('#')+1);  
    if(a!==undefined&&a!==''&&window.location.href.indexOf('#')>0){  
        return a;
    }  
}
function checkEmail(email){
    var check = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
    if(!check.test(email)){
       alert("提示\n\n请输入正确的邮箱");
       return false;
	} else
		return true;
}
function checkIDNum(scard){
	var check = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
	if(!check.test(scard)){
        alert('提示\n\n身份证号码不正确！');
        return false;
	} else
		return true;
}
function checkZipCode(zip){
	var check = /[1-9]\d{5}(?!\d)/;
	if(!check.test(zip)){
        alert('提示\n\n邮编不正确！');
        return false;
	} else
		return true;
}
function checkPhone(phone){
	var check = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
	if(!check.test(phone)){
        alert('提示\n\n手机号码不正确！');
        return false;
	} else
		return true;
}
function checkNull(text,str){
	if(str==null||str.length==0){
    	alert("提示\n\n请填写" + text);
		return false;
	} else
		return true;	
}
function random(){
	return Math.random();
}
function showLoading(id){
	if (!id)
		id = "body";
	else
		id = "#" + id;
	var loading = 	'<div id="loading" class="fakeloader" style="position: fixed; width: 100%; height: 100%; top: 0px; left: 0px;z-index: 999999; background-color:black;opacity:0.6;min-width:1180px;">' + 
				    '    <div class="fl spinner2" style="position: absolute; left: 47%; top: 50%;">' + 
				    '        <div class="spinner-container container_1">' + 
				    '            <div class="circle1"></div>' + 
				    '            <div class="circle2"></div>' + 
				    '            <div class="circle3"></div>' + 
				    '            <div class="circle4"></div>' + 
				    '        </div>' + 
				    '        <div class="spinner-container container_2">' + 
				    '            <div class="circle1"></div>' + 
				    '            <div class="circle2"></div>' + 
				    '            <div class="circle3"></div>' + 
				    '            <div class="circle4"></div>' + 
				    '        </div>' + 
				    '        <div class="spinner-container container_3">' + 
				    '            <div class="circle1"></div>' + 
				    '            <div class="circle2"></div>' + 
				    '            <div class="circle3"></div>' + 
				    '            <div class="circle4"></div>' + 
				    '        </div>' + 
				    '    </div>' + 
				    '</div>';
	$(id).append(loading);			    
}
function hideLoading(){
	$("#loading").remove();
}
// function SetLS(key, json){
// 	$.cookie(key, JSON.stringify(json));
// }

// function GetLS(key){
// 	var str = $.cookie(key);
// 	if (str != null && str != "")
// 		return JSON.parse(str);
// 	else
// 		return false;
// }


var ajaxUrl = {};
function $ajax(opt) {
	showLoading();
	opt.url = Core.API_VER+opt.url;
	if (ajaxUrl[opt.url]) {
		return false;
	}
	ajaxUrl[opt.url] = true;
	opt.dataType = "json";
	opt.type = "post";
	opt.error = function(XMLHttpRequest, textStatus) {
		hideLoading();
		var status = XMLHttpRequest.status;
		if (status == 0)
			return;
		else if (status == 500)
			$alert("服务器错误");
		else
			$alert("请检查您的网络。");
	};
	opt.goSuccess = opt.success;
	opt.success = function(res) {
		hideLoading();
		if (res.code) {
			if (res.code == 6) {
				SetLS("user",null);
				$alert(res.codemsg);
				window.location.href = "/index.html";
			} else {
				$alert(res.codemsg);
				if(res.code == 203) {
					opt.goSuccess(res);
				}else if(res.code == 225) {
					opt.goSuccess(res);
				}else if(res.code == 103)
					opt.goSuccess(res);
			}
		}
		else
			opt.goSuccess(res);
	}
	opt.complete = function() {
		hideLoading();
		delete ajaxUrl[opt.url];
	}
	$.ajax(opt);
}

function $alert(str){
	alert(str);
}
function Id2url(obj, from) {
	var url;
	if (from == "photo") {
		url = Core.IMG_VER + obj;
	} else if (obj.photo) {
		url = Core.IMG_VER + obj.photo;
	} else {
		switch (parseInt(obj.utype)) {
			case UTYPE.TEACHER:
				url = "img/teacher.png";
				break;
			case UTYPE.REG_STUDENT:
			case UTYPE.UN_REG_STUDENT:
				url = "img/student.png";
				break;
		}
	}
	return url;
}

function showCover(text,content,id,value,subFuc, action){
	var courseHtml = '';
	if (action == "chapter")
		courseHtml = '<div style="margin-top: 15px;">'+
	                 '   <label class="radio-inline">'+
	                 '       <input type="radio" name="ctype" value="0" checked="checked"> 正常章节'+
	                 '   </label>'+
	                 '   <label class="radio-inline">'+
	                 '       <input type="radio" name="ctype" value="1"> 阶段性作业'+
	                 '    </label>'+
	                 '   <label class="radio-inline">'+
	                 '       <input type="radio" name="ctype" value="2"> 结业考试'+
	                 '    </label>'+
	                 '</div>';
	if (action == "orderMess")
		courseHtml ='                <p>快递单号</p>'+
				    '				 <input type="text" id="orderId" class="form-control" placeholder="">';           
	var cover = '<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">'+
			    '    <div class="modal-dialog">'+
			    '        <div class="modal-content">'+
			    '            <div class="modal-header">'+
			    '                <button type="button" class="close" data-dismiss="modal">×</button>'+
			    '                <h3>' + text + '</h3>'+
			    '            </div>'+
			    '            <div class="modal-body">'+
			    '                <p>' + content + '</p>'+
			    '				 <input type="text" id="message" data-id="' + id + '" value="' + value + '" class="form-control" placeholder="">'+ courseHtml +
			    '            </div>'+
			    '            <div class="modal-footer">'+
			    '                <a href="#" class="btn btn-default" data-dismiss="modal">关闭</a>'+
			    '                <a href="#" id="fucBtn" class="btn btn-primary" data-dismiss="modal" onclick="' + subFuc + '">保存</a>'+
			    '            </div>'+
			    '        </div>'+
			    '    </div>'+
			    '</div>';
	if ($("#cover").length == 0)
		$("body").append('<div id="cover"></div>');
	$("#cover").html(cover);
    $('#myModal').modal('show');
}

Array.prototype.pushh = function(val) {
	this.push(val);
	return this;
}
Array.prototype.find = function(val, key) {
	if (key) {
		for (var i = 0; i < this.length; ++i) {
			if (this[i][key] == val)
				return i;
		}
	} else {
		for (var i = 0; i < this.length; ++i) {
			if (this[i] == val)
				return i;
		}
	}
	return -1;
}
Array.prototype.remove = function(val, key) {
	if (this.find(val, key) >= 0)
		this.splice(this.find(val, key), 1);
}
String.prototype.replaceAll = function(str1, str2) {
	return this.replace(/str1/g, str2);
}

/** * 对Date的扩展，将 Date 转化为指定格式的String * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q)
    可以用 1-2 个占位符 * 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) * eg: * (new
    Date()).pattern("yyyy-MM-dd hh:mm:ss.S")==> 2006-07-02 08:09:04.423      
 * (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04      
 * (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04      
 * (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04      
 * (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
 */

Date.prototype.pattern = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份
		"d+": this.getDate(), //日
		"h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时 (12小时制)
		"H+": this.getHours(), //小时 (24小时制)
		"m+": this.getMinutes(), //分
		"s+": this.getSeconds(), //秒
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度
		"S": this.getMilliseconds() //毫秒
	};
	var week = {
		"0": "/u65e5",
		"1": "/u4e00",
		"2": "/u4e8c",
		"3": "/u4e09",
		"4": "/u56db",
		"5": "/u4e94",
		"6": "/u516d"
	};
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	if (/(E+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
	}
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		}
	}
	return fmt;
}

Date.prototype.getDayCount = function(year, month) {
	if (!year) {
		year = this.getFullYear();
		month = this.getMonth()+1;
	}

    var count = 0;
    if(month == 2){
        if((year%4 == 0 && year%100 !=0) || (year%400 ==0))
            count = 29;
        else
            count = 28;
    }
    else if(month==1 || month==3 || month==5 || month==7|| month==8 || month==10  || month==12)
        count = 31;
    else if(month==4 || month==6 || month==9 || month==11)
        count = 30;
    return count;
}
Date.prototype.equal = function(date) {
	if (this.getFullYear() == date.getFullYear() &&
		this.getMonth() == date.getMonth() &&
		this.getDate() == date.getDate())
		return true;
	else 
		return false;
}


var CurrentUser = GetLS("user");
$("#TKmoB").click(function(){
    window.open(Core.API_VER + "/qupload/题库模板.xlsx");
})
$(document).on("click", ".backBtn", function(){
	$(".contentEvent").addClass("hidden");
	$("#listContent").removeClass("hidden");
});